package com.mcintyret.site.security;

import com.mcintyret.site.users.User;
import org.springframework.security.authentication.dao.SaltSource;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * User: mcintyret2
 * Date: 08/04/2012
 */

@Component
public class PasswordEncrypter {

    @Resource
    private PasswordEncoder passwordEncoder;
    @Resource
    private SaltSource saltSource;

    public void encryptUserPassword(User user) {
        String oldPassword = user.getPassword();
        String newPassword = passwordEncoder.encodePassword(oldPassword, saltSource.getSalt(user));
        user.setPassword(newPassword);
    }
}
